fix(opencode): resolve heap unlimited + orphan processes on Linux#24297
fix(opencode): resolve heap unlimited + orphan processes on Linux#24297herjarsa wants to merge 1 commit intoanomalyco:devfrom
Conversation
- Add SIGTERM handler in exit.tsx alongside existing SIGHUP handler - Add SIGTERM handler in thread.ts to gracefully stop worker - Add Effect.ensuring to abort AbortController in prompt.ts execRead - Replace unbounded Map with LRU cache in instance.ts (max 20 entries) Fixes anomalyco#15348 This addresses the critical issue where: 1. Processes spawned by opencode on Linux become orphaned when terminal closes 2. AbortController instances accumulate in session prompts causing heap growth 3. Instance cache grows without bound holding references to contexts Closes anomalyco#15348
|
The following comment was made by an LLM, it may be inaccurate: Based on my search results, I found potential related PRs: Related PRs:
These PRs address similar issues (memory management, process cleanup, signal handling), but since PR #24297 (the current PR) is a comprehensive fix specifically addressing the orphan processes + heap growth on Linux, you may want to verify these related PRs are either closed/merged or confirm there's no overlapping work. |
Issue for this PR
Closes #15348
Type of change
What does this PR do?
Fixes critical memory leak and orphan process issues on Linux:
Orphan processes: Added SIGTERM handler alongside existing SIGHUP handler in exit.tsx and hread.ts to ensure graceful shutdown when terminal closes or process receives termination signal.
Heap growth (37+ GB): Added Effect.ensuring to abort AbortController in prompt.ts execRead function. Previously, controllers were only aborted on interrupt, causing accumulation during normal operation.
Unbounded cache: Replaced unbounded Map with LRU cache (max 20 entries) in instance.ts to prevent unbounded growth of instance contexts.
How did you verify your code works?
Checklist